﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VTS.DAL;
using VTS.Common;

namespace VTS.BLL
{
    public class KQHocSinhBLL
    {
        public void Add(string namHoc, string hocKy, string lop,
            string loaiKq, string noidung)
        {
            KQHocSinh kqHocSinh = new KQHocSinh();
            kqHocSinh.NamHoc = int.Parse(namHoc);
            kqHocSinh.HocKy = Utility.CompareString(hocKy, "0") ? false : true;
            kqHocSinh.Lop = int.Parse(lop);
            kqHocSinh.LoaiKQ = loaiKq;
            kqHocSinh.NoiDung = noidung;

            KQHocSinhDAL dalKq = new KQHocSinhDAL();
            dalKq.Add(kqHocSinh);
        }

        public void Update(string namHoc, string hocKy, string lop,
            string loaiKq, string noidung, string Id)
        {
            KQHocSinh kqHocSinh = new KQHocSinh();
            kqHocSinh.MaKQ = int.Parse(Id);
            kqHocSinh.NamHoc = int.Parse(namHoc);
            kqHocSinh.HocKy = Utility.CompareString(hocKy, "0") ? false : true;
            kqHocSinh.Lop = int.Parse(lop);
            kqHocSinh.LoaiKQ = loaiKq;
            kqHocSinh.NoiDung = noidung;

            KQHocSinhDAL dalKq = new KQHocSinhDAL();
            dalKq.Update(kqHocSinh);
        }

        public List<KQHocSinh> GetByNamAndLopAndHocKy(string namHoc, string lop, string hocKy)
        {
            KQHocSinhDAL dalKq = new KQHocSinhDAL();
            List<KQHocSinh> lstKQ = null;

            if (Utility.CompareString(lop, "0") && Utility.CompareString(hocKy, "-1"))
                lstKQ = dalKq.GetByNam(int.Parse(namHoc));
            else if (Utility.CompareString(lop, "0") && !Utility.CompareString(hocKy, "-1"))
                lstKQ = dalKq.GetByHocKyAndNam(Utility.CompareString(hocKy, "0") ? false : true, int.Parse(namHoc));
            else if (!Utility.CompareString(lop, "0") && Utility.CompareString(hocKy, "-1"))
                lstKQ = dalKq.GetLopAndNam(int.Parse(lop), int.Parse(namHoc));
            else
                lstKQ = dalKq.GetByNamAndLopAndHocKy(int.Parse(namHoc), int.Parse(lop), Utility.CompareString(hocKy, "0") ? false : true);

            return lstKQ;
        }

        public void DeleteById(int Id)
        {
            KQHocSinhDAL dalKq = new KQHocSinhDAL();
            dalKq.DeleteById(Id);
        }

        public KQHocSinh GetById(int Id)
        {
            KQHocSinhDAL dalKq = new KQHocSinhDAL();
            return dalKq.GetById(Id);
        }
    }
}
